import java.util.HashSet;
import java.util.Set;

/**
 * 双指针
 * 2025-03-16没做出来
 */
public class _283移动零 {
    public static void moveZeroes(int[] nums) {
        int n = nums.length, left = 0, right = 0;
        while (right < n) {
            if (nums[right] != 0) {
                swap(nums, left, right);
                left++;
            }
            right++;
        }
    }

    public static void swap(int[] nums, int i, int j) {
        int temp = nums[i];
        nums[i] = nums[j];
        nums[j] = temp;
    }


    public static void main(String[] args) {
        int[] a = new int[]{0, 1, 0, 3, 12};
        moveZeroes111(a);
        for (int i : a) {
            System.out.println(i);
        }
    }

    public static void moveZeroes111(int[] nums) {
        int length = nums.length;
        int left = 0;
        int right = 0;
        while (right < length) {
            int n = nums[right];
            if (n != 0) {
                swap(nums, left, right);
                left++;
            }
            right++;
        }
    }


}
